package com.lill.system.web;

import com.lill.common.component.util.OrderNumberUtil;
import com.lill.common.component.util.R;
import com.lill.support.annotation.CurrentUser;
import com.lill.system.model.SysUserEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/sysOrderNumber")
public class SysOrderNumberController {

    /**
     * 前台添加手机号在单号的后面  时间只到时
     * @param paranMap
     * @param user
     * @return
     */
    @RequestMapping("getOrderNum")
    public R getOrderNumber(@RequestParam Map<String,Object> paranMap, @CurrentUser SysUserEntity user){
        Object type = paranMap.get("type");
//        Map<String,Object> map = new HashMap<>();
        String prefix = user.getCompanyCode()+"-"+user.getBranchCode()+"-P";
        if (type != null) {
            prefix += type;
        }
        String orderNumber = prefix+OrderNumberUtil.getOrderNumberYYYYMMDDHH();
        R data = R.ok().put("data", orderNumber);
        return data;
    }

    /**
     * 前台没有手机号   时间到时分秒
     * @param paranMap
     * @param user
     * @return
     */
    @RequestMapping("getOrderNumMMSS")
    public R getOrderNumMMSS(@RequestParam Map<String,Object> paranMap, @CurrentUser SysUserEntity user){
        Object type = paranMap.get("type");
//        Map<String,Object> map = new HashMap<>();
        String prefix = user.getCompanyCode()+"-"+user.getBranchCode()+"-P";
        if (type != null) {
            prefix += type;
        }
        String orderNumber = prefix+OrderNumberUtil.getOrderNumberYYYYMMDDHHMMSS();
        R data = R.ok().put("data", orderNumber);
        return data;
    }
}
